<template>
   <el-dialog
    :visible.sync="dialogVisible"
    @close="close">
     <div slot="title">选择Domain 进行复制</div>
      <el-form
       v-loading="loading"
      hide-required-asterisk
       ref="refForm"
       class="label-row"
      >
        <el-row>
          <el-form-item
              prop="domain"
              label="Domain"
              >
            <el-select
              v-model="refFormData.value"
              size="small"
              filterable
              reserve-keyword
              placeholder="请选择"
            >
              <el-option
                v-for="item in list"
                :key="item.domain"
                :value="item.domain"
                :label="item.domain"
              />
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer" >
          <el-button type="warning" @click="close()">取消</el-button>
          <el-button type="success" @click="submit('refForm')">确认</el-button>
      </span>
  </el-dialog>
</template>

<script>
import { copy2Clipboard } from '@/utils/index'

export default {
  props: {
    info: {
      type: [String, Number],
      default: ''
    },
  },
  components: {
  },
  data() {
    return {
      dialogVisible: true,
      list: [],
      loading: false,
      refFormData: {
         value: ''
      },

    };
  },
  mounted() {
    this.getList();
  },
  methods: {

     /**
      * @Desc 数据提交
      * */
      async submit(val){
        if(!this.refFormData.value) return;
        copy2Clipboard(this.refFormData.value + '/detail/' + this.info)
        this.close()
      },


    copy2Clipboard,
    /*
     * @Desc: 获取列表
     * @params: {String}
     * @return: {Object}
     */
    async getList() {
      this.loading = true;
      const { data } = await this.$api.domain.getList({
        ...this.refFormData,
      });
      this.__globalHandleResponseMixin(data, () => {
        if(data.data[0]) this.refFormData.value = data.data[0].domain
        this.list = data.data;
      });
      this.loading = false;
    },

     /**
      * @Desc 关闭
      * @params {String}
      * @return {Object}
      * */
      close(){
        this.$emit('close')
      }
  },
};
</script>

<style lang="less" scoped>

</style>
